package com.cmf.common;

import com.cmf.enums.ResultCodeType;
import lombok.Data;

/**
 * @Author: cmf
 * @Date: 2025/8/27 16:22
 * @Version: v1.0.0
 * @Description: 结果类封装
 **/
@Data
public class Result<T> {
    private ResultCodeType code;
    private String message;
    private T data;

    public static <T> Result<T> ok(T data) {
        Result<T> result = new Result<>();
        result.setCode(ResultCodeType.SUCCESS);
        result.setData(data);
        return result;
    }
    public static <T> Result<T> ok() {
        return ok(null);
    }
    public static <T> Result<T> error(ResultCodeType code) {
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMessage(code.getDesc());
        return result;
    }
    public static <T> Result<T> error(ResultCodeType code, String message) {
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

}
